Lista de paquetes espaciales en R https://cran.r-project.org/web/views/Spatial.html
Paquetes generales:
Guide to reproducible code (British Ecology Society)
└── my_awesome_project
├── src
├── output
├── data
│ ├── raw
│ └── processed
├── README.md
├── run_analyses.R
└── .gitignore
Fuente: https://www.r-bloggers.com/structuring-r-projects/
librerias y datos dentro del script (shortcut: Crtl+Shift+R)1 or 2 or 4000 or 10e9...
"Hola mundo"
"TRUE" or "FALSE"
c(1, 2) or c("uno", "dos")
## [,1] [,2]
## [1,] "1" "Bucaramanga"
## [2,] "2" "Bogotá"
## Num Nombre
## 1 1 Bucaramanga
## 2 2 Bogotá
x <- c(-73)
y <- c(7.13)
## Colombia continental
## Punta gallinas (lat= 12.46, lon = -71.67)
## Isla San José, Rio Negro Guainia Colombia (1.34, -66.7)
## Cabo Manglares (1.65, -79.01)
## Leticia (-4.23, -69.95)
plot(x, y, xlim = c(-79.01, -66.7), ylim = c(-4.23, 12.46))
# Bogotá
abline(h = 4.71, v = -74.07)## Quibdo 5.69, -76.65 (max 851.7 mm)
## Medellin 6.24, -75.76 (226.7 mm)
## Bogota 4.71, -74.07 (119 mm)
## Bucaramanga 7.13, -73 (149 mm)
lon = c(-76.65, -75.76, -74.07, -73)
lat = c(5.69, 6.24, 4.71, 7.13)
ciudades = cbind(lon, lat)
precip = c(852, 227, 119, 149)
psize <- 1 + precip/500
plot(ciudades, cex=psize, pch=20, col='red', main='Precipitación', xlim = c(-79.01, -66.7), ylim = c(-4.23, 12.46))https://rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf
library(tidyverse)
ciudades2 <- data.frame(x = lon, y = lat, precip = precip, nombre = c("Quibdo", "Medellín", "Bogotá", "Bucaramanga"))
ciudades2 %>%
ggplot(aes(x = lon, y = lat)) +
geom_point(size = 1 + precip/500) +
xlim(c(-79.01, -66.7)) +
ylim(c(-4.23, 12.46)) ## Ejercicio
library(sp)
library(mapview)
library(tmap)
ciudades_geo <- ciudades2
coordinates(ciudades_geo) <- ~x+y## [1] "SpatialPointsDataFrame"
## attr(,"package")
## [1] "sp"
## class : SpatialPointsDataFrame
## features : 4
## extent : -76.65, -73, 4.71, 7.13 (xmin, xmax, ymin, ymax)
## crs : NA
## variables : 2
## names : precip, nombre
## min values : 119, Bogotá
## max values : 852, Quibdo
Forma en que los datos espaciales son “aplanados” en un espacio 2D
“Alineación incorrecta de dos objetos espaciales = diferentes proyecciones”
Fuente: National Ecological Observatory Network (NEON)
Fuente: Maning Sambale
## class : SpatialPointsDataFrame
## features : 4
## extent : -76.65, -73, 4.71, 7.13 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
## variables : 2
## names : precip, nombre
## min values : 119, Bogotá
## max values : 852, Quibdo
Coordenadas X y Y de las esquinas en el espacio geográfico
Fuente: National Ecological Observatory Network (NEON)
## Checking rgeos availability: TRUE
## class : SpatialPolygonsDataFrame
## features : 246
## extent : -180, 180, -90, 83.57027 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0
## variables : 11
## names : FIPS, ISO2, ISO3, UN, NAME, AREA, POP2005, REGION, SUBREGION, LON, LAT
## min values : , AD, ABW, 4, Aaland Islands, 0, 0, 0, 0, -178.131, -80.446
## max values : ZI, ZW, ZWE, 894, Zimbabwe, 1638094, 1312978855, 150, 155, 179.219, 78.83
Col_inx <- which(wrld_simpl$NAME == "Colombia")
Col_poly <- wrld_simpl[Col_inx,]
plot(Col_poly)
plot(ciudades_geo, add = TRUE, col = "red", cex = 1 + ciudades_geo$precip/500, pch = 16)Col_inx <- which(wrld_simpl$NAME == "Colombia")
Col_poly <- wrld_simpl[Col_inx,]
plot(Col_poly, axes = TRUE, col = "lightyellow")
plot(ciudades_geo, col = "orange", cex = 1 + ciudades_geo$precip/500, pch = 16, add = TRUE)plot(wrld_simpl, xlim = c(-81,-67), ylim = c(-4,12), axes = TRUE, col = "lightyellow")
plot(ciudades_geo, col = "orange", cex = 1 + ciudades_geo$precip/500, pch = 20, add = TRUE)plot(wrld_simpl, xlim = c(-81,-67), ylim = c(-4,12), axes = TRUE, col = "lightyellow")
plot(Col_poly, col = "orange", add = TRUE)
plot(ciudades_geo, col = "red", cex = 1 + ciudades_geo$precip/500, pch = 20, add = TRUE)Lista de proyecciones disponibles
wrld_simpl2 <- spTransform(wrld_simpl, CRS("+proj=laea"))
par(mfrow = c(1,2))
plot(wrld_simpl)
plot(wrld_simpl2)## Lambert Azimuthal Equal Area
ciudades_geo2 <- spTransform(ciudades_geo, CRS("+proj=laea"))
par(mfrow = c(1,2))
plot(ciudades_geo, col = "red", pch = 16, axes = TRUE)
plot(ciudades_geo2, col = "blue", pch = 16, axes = TRUE)plot(Col_poly, col = "orange", axes = TRUE)
plot(ciudades_geo2, col = "red", cex = 1 + ciudades_geo$precip/500, pch = 20, add = TRUE)Col_poly2 <- spTransform(Col_poly, CRS("+proj=laea"))
plot(Col_poly2, col = "orange", axes = TRUE)
plot(ciudades_geo2, col = "red", cex = 1 + ciudades_geo$precip/500, pch = 20, add = TRUE)SpatialPointsDataFrameFuente: National Ecological Observatory Network (NEON)
Tamaño de cada cuadrícula (usualmente en metros)
Fuente: National Ecological Observatory Network (NEON)
Variables bioclimáticas de la base de datos de Worldclim (Hijmans et al., 2004) http://worldclim.org/bioclim
library(dismo)
# Descargar los datos directamente
bio_ly <- getData("worldclim", var="bio", res=10, path="./data/")
## Group of raster layers
class(bio_ly)
names(bio_ly)
tempRast <- bio_ly$bio1/10
precipRast <- bio_ly$bio12
tempRast
precipRast ##
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
##
## select
## The following object is masked from 'package:tidyr':
##
## extract
## class : RasterLayer
## dimensions : 900, 2160, 1944000 (nrow, ncol, ncell)
## resolution : 0.1666667, 0.1666667 (x, y)
## extent : -180, 180, -60, 90 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
## source : /home/se1212/Git_repos/UIS_course/Intro_Analisis_Espacial/data/wc10/bio12.bil
## names : bio12
## values : 0, 9916 (min, max)
## [1] 7399 1965 863 1204
## precip nombre precip_bioclim
## 1 852 Quibdo 7399
## 2 227 Medellín 1965
## 3 119 Bogotá 863
## 4 149 Bucaramanga 1204
## $breaks
## [1] 0 2 4 6 8 10
##
## $counts
## [1] 4732 23187 210982 334984 8996
##
## $density
## [1] 0.004059148 0.019889995 0.180982053 0.287351964 0.007716841
##
## $mids
## [1] 1 3 5 7 9
##
## $xname
## [1] "v"
##
## $equidist
## [1] TRUE
##
## attr(,"class")
## [1] "histogram"
# Using the raster object with different breaks
plot(log(precipRast),
breaks = preciHist$breaks,
col = brewer.pal(5, "Spectral"))plot(log(col_ras),
breaks = preciHist$breaks,
col = brewer.pal(5, "Spectral"))
plot(Col_poly, add = TRUE)Usando otra capa climática de bioclim (e.g., temperatura anual media):
ciudades_geo